home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / dsp4src / qrmqrn.lst < prev    next >
Encoding:
File List  |  1994-04-01  |  9.3 KB  |  238 lines

  1.  
  2. Motorola DSP56000 Assembler  Version 3.1  94-04-01  19:55:55  qrmqrn.asm  Page 1
  3.  
  4.  
  5.  
  6. 1                                  page    132,79,1,1
  7. 2                                  opt     rc
  8. 4      
  9. 5                        ;***************************************************************
  10. 6                        ;* QRMQRN.ASM -- LMS Automatic Notch and Noise Filter          *
  11. 7                        ;*                                                       *
  12. 8                        ;* Provides Automatic Notch Filter (QRM reductor) and          *
  13. 9                        ;* Noise Filter (QRN reductor) based on the LMS algorithm.     *
  14. 10                       ;* When compiled with 0=0 noise filter code is activated.  *
  15. 11                       ;* When compiled with 0=1 automatic 0 filter code is   *
  16. 12                       ;* activated.                                             *
  17. 13                       ;*                                                       *
  18. 14                       ;* This implementation is for Alef Null DSP CARD 4 with        *
  19. 15                       ;* Leonid monitor.                                         *
  20. 16                       ;*                                                       *
  21. 17                       ;* Algoriths are based on the book and article                *
  22. 18                       ;*      Candy, J., V.:                                    *
  23. 19                       ;*      "Signal Processing, The Modern Approach",             *
  24. 20                       ;*      McGraw-Hill, 1988                                  *
  25. 21                       ;*                                                       *
  26. 22                       ;*      Reyer, S., Hershberger, D.:                         *
  27. 23                       ;*      "Using The LMS Algorithm For QRM and QRN Reduction",   *
  28. 24                       ;*      QEX, September 1992                                *
  29. 25                       ;*                                                       *
  30. 26                       ;* Copyright (C) 1993 by Alef Null. All rights reserved.       *
  31. 27                       ;* Author(s): Jarkko Vuori, OH2LNS                           *
  32. 28                       ;* Modification(s):                                        *
  33. 29                       ;***************************************************************
  34. 30     
  35. 31     
  36. 243    
  37. 244    
  38. 245       000018         lmslen    equ     24        ; LMS filter lenght
  39. 246       000008         buflen    equ     8         ; lenght of sample buffer
  40. 247    
  41. 248                                if      0
  42. 253                                else
  43. 254                      ; Denoiser constants
  44. 255       000001         dlen      equ     1         ; delay line lenght
  45. 256       1.875000E-001  beta      equ     0.1875    ; adaptation coefficient
  46. 257       9.804700E-001  decay     equ     0.98047   ; coefficient decay value
  47. 258                                endif
  48. 259    
  49. 260    
  50. 261       P:0040                   org     p:user_code
  51. 262    
  52. 263                      ; initialize address registers
  53. 264       P:0040 372200            move              #<buffer+2,r7 ; interrupt handler pointer
  54. 265       P:0041 051FA7            move              #buflen*4-1,m7
  55. 266    
  56. 267       P:0042 364000            move              #<lmscoef,r6 ; LMS filter coeff pointer
  57. 268    
  58. 269       P:0043 351800            move              #<iircoef,r5 ; IIR filter coeff pointer
  59. 270       P:0044 0503A5            move              #4-1,m5
  60. 271    
  61. 272       P:0045 322000            move              #<buffer,r2 ; sample buffer read pointer
  62. 273       P:0046 3A0200            move              #4-2,n2
  63. 274       P:0047 051FA2            move              #buflen*4-1,m2
  64. 275    
  65. 276       P:0048 314000            move              #<dline,r1  ; delay line sample pointer
  66. 277       P:0049 0518A1            move              #dlen+lmslen-1,m1
  67. 278    
  68. 279                      ; initialize codec
  69. 280                      ; fs = 16 kHz, line input, headphones and line output, no gain and attenuation
  70. 281                                ctrlcd  1,r2,buflen,LINEI,0.0,0.0,LINEO|HEADP,0.0,0.0
  71. 302                                opencd  16
  72. 331    
  73. 332                      ; wait for one sample
  74. 333                      loop      waitblk r2,buflen,1
  75. 351       P:0066 44DA00            move              x:(r2)+,x0  ; read sample from the left channel
  76. 352    
  77. 353                      ; highpass filter the input signal (with one biquad IIR section)
  78. 354       P:0067 45F400            move              #0.5*g,x1   ; scale input signal
  79.  
  80.  
  81. Motorola DSP56000 Assembler  Version 3.1  94-04-01  19:55:55  qrmqrn.asm  Page 2
  82. LMS AutoNotcher/Denoiser
  83.  
  84.  
  85.                  0072B0
  86. 355       P:0069 3018A0            mpy     x0,x1,a   #<iirs,r0
  87. 356    
  88. 357       P:006A 000BF8            ori     #$0b,mr   ; set left shift scaling mode
  89. 358       P:006B F0B800            move              x:(r0)+,x0  y:(r5)+,y0  ; s1, a1
  90. 359       P:006C F4A0D6            mac     -x0,y0,a  x:(r0),x1   y:(r5)+,y0  ; s2, a2
  91. 360       P:006D F030E7            macr    -x1,y0,a  x0,x:(r0)-  y:(r5)+,y0  ; new s2, get b1
  92. 361       P:006E F820D2            mac     x0,y0,a   a,x:(r0)    y:(r5)+,y0  ; new s1, get b2
  93. 362       P:006F 2000E3            macr    x1,y0,a
  94. 363       P:0070 00F4B8            andi    #$f4,mr   ; restore scaling mode
  95. 364    
  96. 365       P:0071 21C400            move              a,x0        ; back scaling
  97. 366       P:0072 45F400            move              #>@cvi(1.0/g+.5),x1
  98.                  00008F
  99. 367       P:0074 2000A0            mpy     x0,x1,a
  100. 368       P:0075 200022            asr     a         ; adjust binary point
  101. 369       P:0076 505900            move              a0,x:(r1)+
  102. 370       P:0077 210500            move              a0,x1
  103. 371    
  104. 372                      ; Wiener filter convolution part
  105. 373       P:0078 F0D913            clr     a         x:(r1)+,x0  y:(r6)+,y0
  106. 374       P:0079 0617A0            rep     #lmslen-1
  107. 375       P:007A F0D9D2            mac     x0,y0,a   x:(r1)+,x0  y:(r6)+,y0
  108. 376       P:007B E0D1D3            macr    x0,y0,a   x:(r1)-,x0  y:(r6)-,y0
  109. 377    
  110. 378                                if      !0
  111. 379                      ; store FIR output as a program output if denoiser code
  112. 380       P:007C 5E5A00            move                          a,y:(r2)+   ; left channel
  113. 381       P:007D 5E4A00            move                          a,y:(r2)+n2 ; right channel
  114. 382                                endif
  115. 383    
  116. 384                      ; calculate error (e = D - Y) to x1
  117. 385       P:007E 47F436            neg     a         #decay,y1
  118.                  7D800A
  119. 386       P:0080 241860            add     x1,a      #beta,x0
  120. 387       P:0081 21C500            move              a,x1
  121. 388    
  122. 389                                if      0
  123. 393                                endif
  124. 394    
  125. 395                      ; Wiener filter adaptation part
  126. 396       P:0082 22D4A1            mpyr    x0,x1,a   r6,r4       ; x1 = beta * e
  127. 397       P:0083 21C500            move              a,x1
  128. 398    
  129. 399       P:0084 E0D100            move              x:(r1)-,x0  y:(r6)-,y0  ; get x(0), c(0)
  130. 400       P:0085 2000B0            mpy     y0,y1,a
  131. 401       P:0086 E0D1A3            macr    x0,x1,a   x:(r1)-,x0  y:(r6)-,y0  ; c(0) = decay * c(0) + e * x(0)
  132. 402       P:0087 061780            do      #lmslen-1,adaloop
  133.                  00008A
  134. 403       P:0089 5E54B0            mpy     y0,y1,a               a,y:(r4)-   ; save new c
  135. 404       P:008A E0D1A3            macr    x0,x1,a   x:(r1)-,x0  y:(r6)-,y0  ; c(n) = decay * c(n) + e * x(n)
  136. 405                      adaloop
  137. 406       P:008B 5E5400            move                          a,y:(r4)-   ; save c(N)
  138. 407       P:008C F0D900            move              x:(r1)+,x0  y:(r6)+,y0
  139. 408       P:008D F0D900            move              x:(r1)+,x0  y:(r6)+,y0
  140. 409    
  141. 410                      ; and do this forever
  142. 411       P:008E 0C0058            jmp     <loop
  143. 412    
  144. 413    
  145. 414       X:0018                   org     x:user_data
  146. 415    
  147. 416       X:0018         iirs      ds      2         ; highpass IIR states
  148. 417    
  149. 418       X:0020         buffer    dsm     buflen*4  ; input sample buffer
  150. 419    
  151. 420       X:0040         dline     dsm     dlen+lmslen ; delay line and LMS states
  152. 421    
  153. 422    
  154. 423       Y:0018                   org     y:user_data
  155. 424    
  156. 425                      ; 0.5 dB/40 dB elliptic IIR HPF
  157. 426                      ; pass 300 Hz, rej 35 Hz
  158.  
  159.  
  160. Motorola DSP56000 Assembler  Version 3.1  94-04-01  19:55:55  qrmqrn.asm  Page 3
  161. LMS AutoNotcher/Denoiser
  162.  
  163.  
  164. 427       7.000000E-003  g         equ     0.007     ; biquad filter scaler
  165. 428       Y:0018         iircoef   dc      -1.880563819/2.0,0.8990682309/2.0 ; biquad filter coeffs, a1, a2
  166. 429       Y:001A                   dc      -1.999905221/2.0,1.0/2.0 ;                    b1, b2
  167. 430    
  168. 431       Y:0020                   dsm     buflen*4  ; output sample buffer
  169. 432    
  170. 433       Y:0040         lmscoef   dsm     lmslen    ; LMS filter coefficients
  171. 434    
  172. 435                                end
  173.  
  174. 0    Errors
  175. 0    Warnings
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.